﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FCTC_Web.Models;
using DAL;
using FCTC_Web.Utilities;
using System.Drawing;
using System.IO;

namespace FCTC_Web.Controllers
{
    public class UploadController : Controller
    {
        public ActionResult AjaxUploadImg(HttpPostedFileBase file)
        {
            long FileSize = long.Parse(System.Configuration.ConfigurationManager.AppSettings["FileSize"].ToString());
            if (file.ContentLength > FileSize)
            {
                return new FileUploadJsonResult { Data = new {status="failed", message = string.Format("{0}", "文件过大！超过上传限制") } };
            }
            else if (!file.ContentType.Contains("image"))
            {
                return new FileUploadJsonResult { Data = new { status = "failed", message = string.Format("{0}", "不是有效的图片文件!") } };
            }
            else
            {
                var filename = Path.GetFileName(file.FileName);
                var path = Path.Combine(Server.MapPath("~/upload"), filename);
                file.SaveAs(path);
                return new FileUploadJsonResult { Data = new { status = "sucess", message = string.Format("{0}", filename) } };
            }
               
        }

    }
}
